<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../vue.js"></script>
  </head>
  <body>
    <div id="app">
      <button @click="addFront">前面加一个</button>
      <button @click="addQueen">后面加一个</button>
      <br>
      <h1>遍历数组</h1>
      <ul>
        <li v-for="item , index in arr" :key="item.id">
            姓名:{{item.name}}----性别：{{item.sex}}
        </li>
      </ul>
      <br>
      <br>
      <hr>
      <h1>遍历对象</h1>
      <p v-for="item,index in obj">
        {{item}} --- {{index}}
      </p>
      <br>
      <br>
      <hr>
      <h1>遍历字符串</h1>
      <p v-for="item,index in str">
        {{item}}---{{index}}
      </p>
      <br>
      <br>
      <hr>
      <h1>遍历数字</h1>
      <p v-for="item,index in num">
        {{item}}---{{index}}
      </p>
    </div>

    <script>
      Vue.config.productionTip = false;

      const vm = new Vue({
        el: "#app",
        data() {
          return {
            obj: {
              name: "社会我王哥",
              age: 8,
              sex: "男",
            },
            arr: [
              { id: "001", name: "lick", sex: "nan" },
              { id: "002", name: "tick", sex: "nv" },
              { id: "003", name: "lack", sex: "nan" },
            ],
            str: "abcdefg",
            num: 10,
          };
        },
        methods: {
          addFront() {
            this.arr = [
              { id: Date.now(), name: "xiaoge~", sex: "nan" },
              ...this.arr,
            ];
          },
          addQueen() {
            this.arr = [
              ...this.arr,
              { id: Date.now(), name: "xiaohei~", sex: "nan" },
            ];
          },
        },
      });
    </script>
  </body>
</html>
